#coding:utf-8


import pickle
import ConfigParser
import sys,os
#import time

def load(filename):
    f = open(filename, 'r')
    try:
        x = pickle.load(f)
    except IndexError:
        x = None
    f.close()
    return x

def loads(str):
    return pickle.loads(str)



def dump(obj, filename):
    f = open(filename, 'w')
    pickle.dump(obj, f)
    f.close()
    return True

def dumps(obj):
    return pickle.dumps(obj)

class ConfigIni:
    def __init__(self, filename):
        self.config = ConfigParser.RawConfigParser()
        self.filename = filename
        self.config.read(self.filename)
        self.set('NAME', 'name', 'vehiclehunter')
    
    def get(self, section, option, default = None):
        try:
            v = self.config.get(section, option)
        except ConfigParser.NoSectionError:
            self.config.add_section(section)
            self.set(section, option, default)
            v = default
        except ConfigParser.NoOptionError:
            self.set(section, option, default)
            v = default
        return v
    
    def set(self, section, option, value):
        try:
            self.config.set(section, option, value)
        except ConfigParser.NoSectionError:
            self.config.add_section(section)
            self.config.set(section, option, value)

    def save(self):
        f = open(self.filename, 'w')
        self.config.write(f)
        f.close()